<?php

namespace app\business\controller;

use think\Controller;
use Util\SysDb;

class Shop extends Controller
{
    public function shopall()
    {
        $this->db = new SysDb();
        $admin = $this->db->table('bus_shop')->lists();
        if (!$admin) {
            exit(json_encode(['code' => 1, 'message' => 'error',"result"=>"无店铺" ]));
        }else{
            exit(json_encode(['message' =>'succ','result'=>$admin]));
        }
    }
    public function shopdetele()
    {
        $id = trim(input('param.ids'));
        $this->db = new SysDb();
        $admin = $this->db->table('bus_shop')->where(['id' => $id])->delete();
        if (!$admin) {
            exit(json_encode(['code' => 1, 'message' => 'error',"result"=>"无店铺" ]));
        }else{
            exit(json_encode(['message' =>'succ','result'=>$admin]));
        }
    }
    public function shopadd()
    {

        $type = trim(input('param.type'));
        $name =trim(input('param.name'));
        $data['tenant_id']=1;
        $data['bus_id']=null;
        $data['shop_id']=null;
        $data['access_token']=null;
        $data['remark']=null;
        $data['status']=1;
        $data['type']=$type;
        $data['name']=$name;
        $data['create_time']=date('Y-m-d h:i:s', time());
        $this->db = new SysDb();
        $admins = $this->db->table('bus_shop')->where(['type' => $type])->where(['name' => $name])->item();
       
        if ($admins) {
            exit(json_encode(['code' => 1, 'message' => 'error',"result"=>"店铺已经存在" ]));
        }else{
            $admin = $this->db->table('bus_shop')->insert($data);
            exit(json_encode(['code' => 1, 'message' => 'succ',"result"=>"添加成功" ]));
        }
    }
}
